#!/bin/bash

# 本处理必须在安装tomcat以后，因为需要验证 $HRS_TOMCAT_HOME/bin/conf 下的yarn-site.xml文件
function fenfa_jars()
{
  echo_start "$1 ... ..."
  
  confirm_operate "fenfa jars"
  if [ $? -eq 0 ]; then
    # 获取安装介质中fenfa目录下的所有文件
    local fenfaJars=$(cd $HYREN_USERPD_DIR/fenfa; ls *.jar) || { die "can not getting fenfa jars"; }
    local localJarNums=$(ls -l $HYREN_USERPD_DIR/fenfa/*.jar|wc -l)
    local value_arr=($HYREN_ALLHOSTS)
    for i in ${value_arr[@]}; do
      echo_doing "  host : $i >>>>>> "
      ssh -o StrictHostKeyChecking=no $i "if [ ! -d $HRS_FENFA_HOME ]; then mkdir -p $HRS_FENFA_HOME; fi" || { die "make $HRS_FENFA_HOME fail on $i"; }
      ssh -o StrictHostKeyChecking=no $i "if [ -d $HRS_FENFA_HOME ]; then rm -rf $HRS_FENFA_HOME/*; fi" || { die "clean $HRS_FENFA_HOME fail on $i"; }
      scp $HYREN_USERPD_DIR/fenfa/*.jar $i:$HRS_FENFA_HOME >> $SETUP_LOGFILE || { die "scp jars to [${i}] fail."; }
#      for curjar in ${fenfaJars[@]}; do
#        ssh $i test -f "$HRS_FENFA_HOME/$curjar" > /dev/null 2>&1 || scp "$HYREN_USERPD_DIR/fenfa/$curjar" $i:$HRS_FENFA_HOME >> $SETUP_LOGFILE || { die "scp jars to [${i}] fail."; }
#      done
#      ssh -o StrictHostKeyChecking=no $i "chown -R $HYREN_USER:$HYREN_USER $HRS_FENFA_HOME" || { die "chown $HRS_FENFA_HOME fail on $i"; }
#      local remoteJarNums=$(ssh -o StrictHostKeyChecking=no $i "ls -l $HRS_FENFA_HOME/*.jar|wc -l")
#      if [ $localJarNums -ne $remoteJarNums ]; then
#        die "fenfa fail local jars[$HYREN_USERPD_DIR/fenfa] not equal to $i jars[$HRS_FENFA_HOME]"
#      fi
      echo_done
    done
    unset value_arr
    unset fenfaJars
    unset localJarNums
    unset i
#    unset curjar
#    unset remoteJarNums
#    echo_success "$1"
    echo_passed "$1 done."
  else
    echo_passed "$1 SKIP"
  fi
}
